{extend name="main_mobile"}
{block name="style"}
<style type="text/css">
	.flex-lable{width: 100px;color: #6c757d;text-align: right;padding-right: 10px;}
	.w-100px{width: 100px;}
</style>
{/block}
{block name="body"}
<div class="bg-white mb-3 table-responsive p-3">
	<el-form :model="search" @submit.native.prevent="submitForm" ref="search"
	  label-position="right">

	  	<div class="flex flex-center">
		  	<div>
			  	<el-select v-model="search.search_type" placeholder="请选择" class="w-80px">
				    <el-option key="uid"label="UID"value="uid"></el-option>
				    <el-option key="user"label="用户名"value="user"></el-option>
				    <el-option key="mobile"label="手机号"value="mobile"></el-option>
				    <el-option key="email"label="邮箱"value="email"></el-option>
				</el-select>
		  	</div>
		  	<div class="mx-1 flex-1">
		    	<el-input v-model="search.key" placeholder="请输入你想搜索的关键词" clearable></el-input>
		  	</div>
		    <el-button type="primary" @click="sendHtml">查询</el-button>
		    <span class="text-nowrap px-2 py-3 small text-secondary"
		    @click="searchMore= !searchMore">{{searchMore?'收起':'更多'}}</span>
	  	</div>
	  	<div v-show="searchMore" style="display: none;" class="mt-3">
		  	<el-form-item label="状态" prop="status">
			  	<el-select v-model="search.status" placeholder="请选择">
				    <el-option key="all"label="全部"value="all"></el-option>
				    <el-option :key="1"label="正常":value="1"></el-option>
				    <el-option :key="0"label="禁用":value="0"></el-option>
				</el-select>
		  	</el-form-item>

		  	<el-form-item label="身份" prop="role_type">
			  	<el-select v-model="search.role_type" placeholder="请选择">
				    <el-option key="all"label="全部"value="all"></el-option>
				    <el-option :key="1"label="企业":value="1"></el-option>
				    <el-option :key="0"label="个人":value="0"></el-option>
				</el-select>
		  	</el-form-item>
	  	</div>
	</el-form>
</div>
<div class="bg-white mb-2 p-3" v-for="(v,index) in tableData">
	<div class="flex flex-center">
	  	<div class="flex flex-center flex-1">
			<el-image
			  	v-if="v.headimg" 
			    style="width: 30px; height: 30px"
			    lazy
			    class="rounded-circle mr-2"
			    :src="v.headimg" 
			    :preview-src-list="[v.headimg]">
			</el-image>
	  		<div class="text-small">
		      	<div>{{v.nickname}}</div>
	      		<div>{{ v.user }}</div>
	  		</div>
	  	</div>
	  	<div class="text-secondary text-small">UID:{{v.id}}</div>
	</div>
	<div class="flex pt-2">
		<div class="flex-1 flex flex-center">
			<div class="w-50px text-grey">手机号</div>
			<div class="flex-1">{{ v.mobile }}</div>
		</div>
		<div class="flex-1 flex flex-center">
			<div class="w-50px text-grey">状态</div>
			<div class="flex-1">
		      	<transition>
		      		<el-button type="success" size="minism"
		      		v-if="v.status==1 || v.status==2" 
		      		@click="setStatus(v);" 
		      		:loading="v.status==2">正常</el-button>
		      		<el-button type="info" size="minism" 
		      		v-else="v.status==0 || v.status==2" 
		      		@click="setStatus(v);" 
		      		:loading="v.status==2">禁用</el-button>
				</transition>
			</div>
		</div>
	</div>
	<div class="flex pt-2">
		<div class="flex-1 flex flex-center">
			<div class="w-50px text-grey">邮箱</div>
			<div class="flex-1">{{ v.email }}</div>
		</div>
		<div class="flex-1 flex flex-center">
			<div class="w-50px text-grey">身份</div>
			<div class="flex-1 flex flex-center">
	      		<span class="text-primary" 
	      		v-if="v.role_type==1">企业</span>
	      		<span class="text-info"
	      		v-else="v.role_type==0">个人</span>
	      		<div class="text-small text-primary pointer ml-3"
	      		@click="toggleRoleType(v)">转换身份</div>
			</div>
		</div>
	</div>
	<div class="flex flex-center pt-3">
		<div class="flex-1 text-grey text-small">{{v.create_time}}通过{{v.app_name}}注册</div>
		<el-button round size="mini" @click="getUserInfo(v)">查看</el-button>
	</div>
</div>
<div class="table-responsive py-3 text-center">
	<el-pagination
	  background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="search.page"
      :page-sizes="[10,50,100,200]"
      :page-size="search.pageSize"
      layout="total, sizes, prev, next"
      :total="search.total">
    </el-pagination>
</div>
<el-dialog
  title="用户信息"
  :visible.sync="userDialogVisible"
  width="100%"
  top="0"
  :before-close="cancelRefuseWinSubmit"
  custom-class="mb-0">
	<div v-if="UserFind.id">
      	<div v-if="UserFind.user_info==1">
      		<div>
      			<div class="flex flex-center pb-3">
      				<div class="flex-lable">UID</div>
      				<div class="flex-1">{{UserFind.data.id}}</div>
      			</div>
      			<div class="flex flex-center pb-3">
      				<div class="flex-lable">用户</div>
					<el-image
					  	v-if="UserFind.data.headimg" 
					    style="width: 30px; height: 30px"
					    lazy
					    class="rounded-circle mr-2"
					    :src="UserFind.data.headimg" 
					    :preview-src-list="[UserFind.data.headimg]">
					</el-image>
      				<div class="flex-1">
						{{UserFind.data.nickname}}
      				</div>
      			</div>
      			<div class="flex flex-center pb-3">
      				<div class="flex-lable">账号</div>
      				<div class="flex-1">{{UserFind.data.user}}</div>
      			</div>
      			<div class="flex flex-center pb-3">
      				<div class="flex-lable">手机号</div>
      				<div class="flex-1">{{UserFind.data.mobile}}</div>
      			</div>
      			<div class="flex flex-center pb-3">
      				<div class="flex-lable">邮箱</div>
      				<div class="flex-1">{{UserFind.data.email}}</div>
      			</div>
      			<div class="flex flex-center pb-3">
      				<div class="flex-lable">实名</div>
      				<div class="flex-1" v-if="UserFind.data.name">{{UserFind.data.name}} {{UserFind.data.idcard}}</div>
      				<div class="flex-1 text-secondary" v-else="UserFind.data.name">未实名</div>
      			</div>
      			<div class="flex flex-center pb-3">
      				<div class="flex-lable">当前身份</div>
      				<div class="flex-1 text-primary" 
      				v-if="UserFind.data.role_type">企业</div>
      				<div class="flex-1 text-success" 
      				v-else="UserFind.data.role_type">个人</div>
      			</div>
      			<div class="flex flex-center pb-3" v-if="UserFind.data.pid">
      				<div class="flex-lable">上级</div>
      				<div>
						<el-image
						  	v-if="UserFind.data.pheadimg" 
						    style="width: 30px; height: 30px"
						    lazy
						    class="rounded-circle mr-2"
						    :src="UserFind.data.pheadimg" 
						    :preview-src-list="[UserFind.data.pheadimg]">
						</el-image>
					</div>
      				<div class="flex-1">
						{{UserFind.data.pid}}{{UserFind.data.pnickname}}
      				</div>
      			</div>
      			<div class="flex flex-center pb-3">
      				<div class="flex-lable">绑定QQ</div>
      				<el-link
      				v-if="UserFind.data.bind_qq"
      				type="primary"
      				:underline="false">{{UserFind.data.bind_qq.nickname}}</el-link>
      				<el-link
      				v-else
      				type="info"
      				:underline="false">未绑定</el-link>
      			</div>
      			<div class="flex flex-center pb-3">
      				<div class="flex-lable">绑定微信</div>
      				<el-link
      				v-if="UserFind.data.bind_wx"
      				type="primary"
      				:href="'/wxUser?uid='+UserFind.id"
      				target="_blank"
      				:underline="false">{{UserFind.data.bind_wx.nickname}}</el-link>
      				<el-link
      				v-else
      				type="info"
      				:underline="false">未绑定</el-link>
      			</div>
      			<div class="flex flex-center pb-3">
      				<div class="flex-lable">绑定AppleID</div>
      				<el-link
      				v-if="UserFind.data.bind_apple"
      				type="primary"
      				:underline="false">已绑定</el-link>
      				<el-link
      				v-else
      				type="info"
      				:underline="false">未绑定</el-link>
      			</div>
      			<div class="flex flex-center pb-3">
      				<div class="flex-lable">禁用消息</div>
      				<div class="flex-1">{{UserFind.data.disable_msg}}</div>
      			</div>
      		</div>
      		<div>
      			<el-timeline>
				    <el-timeline-item 
				    :timestamp="UserFind.data.register_time" >
				        <h6>注册</h6>
				        <p class="mb-0 text-secondary small">{{UserFind.data.register_ip}}</p>
				        <p class="mb-0 text-secondary small">{{UserFind.data.register_devices}}</p>
				    </el-timeline-item>
				    <el-timeline-item 
				    :timestamp="UserFind.data.update_time">
				        <h6>账户</h6>
				    </el-timeline-item>
				    <el-timeline-item 
				    :timestamp="UserFind.data.info_update_time">
				        <h6>资料</h6>
				    </el-timeline-item>
				    <el-timeline-item 
				    :timestamp="UserFind.data.login_time">
				        <h6>最后登录</h6>
				        <p class="mb-0 text-secondary small">{{UserFind.data.login_ip}}</p>
				        <p class="mb-0 text-secondary small">{{UserFind.data.login_devices}}</p>
				    </el-timeline-item>
				    <el-timeline-item 
				    :timestamp="UserFind.data.online_time">
				        <h6>最后在线</h6>
				        <p class="mb-0 text-secondary small">{{UserFind.data.online_ip}}</p>
				        <p class="mb-0 text-secondary small">{{UserFind.data.online_devices}}</p>
				    </el-timeline-item>
				</el-timeline>
      		</div>
      	</div>
      	<div class="text-center py-5 text-secondary small" v-else-if="UserFind.user_info==0">
      		<i class="el-icon-loading mr-2"></i>加载中...
      	</div>
      	<div class="text-center py-5 text-secondary small" v-else="UserFind.user_info">
      		未获取到用户信息
      	</div>
	</div>
	<div slot="footer" class="table-responsive text-nowrap">
	    <el-button 
	    	type="primary"
            size="mini"
            @click="window.open('/user/editUser/'+UserFind.id);cancelRefuseWinSubmit();">编辑</el-button>
	    <el-button
            size="mini"
            @click="cancelRefuseWinSubmit">关闭</el-button>
        <el-button
            type="info"
            size="mini"
            @click="window.open('/user/loginLog?uid='+UserFind.id);cancelRefuseWinSubmit();">登录日志</el-button>
        <el-button
            type="info"
            size="mini"
            @click="window.open('/user/apiLog?uid='+UserFind.id);cancelRefuseWinSubmit();">操作日志</el-button>
	</div>
</el-dialog>
<el-dialog
  title="禁止登录"
  :visible.sync="dialogVisible"
  width="100%"
  :before-close="cancelRefuseWinSubmit">
	<el-form :model="disable_form" label-width="80px" :rules="rules" ref="disable_form" size="small" label-position="top">
		  <el-form-item label="禁用原因" prop="msg">
		    <el-input type="textarea" v-model="disable_form.msg" class="col-12 pl-0 pr-0" :autosize="{ minRows: 4, maxRows: 20}" maxlength="200" show-word-limit></el-input>
		  </el-form-item>
		  <el-form-item label="封禁期限" prop="auto_disable">
		    <el-date-picker
		      v-model="disable_form.auto_disable"
		      align="top"
		      type="date"
		      :editable="false"
		      format="yyyy-M-d"
		      value-format="yyyy-M-d"
			  :picker-options="endPickerOptions"
		      placeholder="End Time">
		    </el-date-picker>
		  	<p class="small text-danger">自动解封期限</p>
		  </el-form-item>
	</el-form>
	<div class="pointer text-primary small py-1" @click="showLog= !showLog;">{{showLog?'收起日志':'查看日志'}}</div>
  	<div v-show="showLog" style="max-height:500px;overflow-y: auto;">
		<div class="py-2 border-bottom mb-2" v-for="(v,index) in UserFind.log">
			<div class="flex">
				<div class="text-success" v-if="v.status===1">解除封禁</div>
				<div class="text-danger" v-if="v.status===0">封号</div>
				<div class="flex-1 pl-2">{{v.nickname}}</div>
				<div class="small text-secondary">{{v.create_time}}</div>
			</div>
			<div class="pt-2">{{v.disable_msg}}</div>
			<div class="pt-2 small" v-if="v.auto_time">自动解封日期：{{v.auto_time}}<span v-if="v.auto_status" class="ml-1 text-success">已执行</span></div>
		</div>
  	</div>
	<div slot="footer">
	    <el-button @click="cancelRefuseWinSubmit">取 消</el-button>
	    <el-button type="primary" @click="submitDisable('disable_form');" :loading="disable_form.ajax">{{disable_form.ajax?'提交中...':'提交'}}</el-button>
	</div>
</el-dialog>
{/block}
{block name="script"}
<script type="text/javascript">
	{empty name="role"}
	var role=[];
	{else/}
	var role={:json_encode($role,JSON_UNESCAPED_UNICODE)};
	{/empty}
</script>
<script type="text/javascript">
	var vm=new Vue({
		el:'#app',
		data:{
			view:XYBase.view,
			role:role,
			labelPosition:'right',
			searchMore:false,
			showLog:false,
			userDialogVisible:false,
			dialogVisible:false,
			UserFind:{},
		    endPickerOptions: {
		        disabledDate(time) {
		          return time.getTime() < Date.now();
		        },
		        shortcuts: [{
		            text: '1天',
		            onClick(picker) {
		              const date = new Date();
		              date.setTime(date.getTime() + 3600 * 1000 * 24);
		              picker.$emit('pick', date);
		            }
		        }, {
		            text: '3天',
		            onClick(picker) {
		              const date = new Date();
		              date.setTime(date.getTime() + 3600 * 1000 * 24 * 3);
		              picker.$emit('pick', date);
		            }
		        }, {
		            text: '7天',
		            onClick(picker) {
		              const date = new Date();
		              date.setTime(date.getTime() + 3600 * 1000 * 24 * 7);
		              picker.$emit('pick', date);
		            }
		        }, {
		            text: '15天',
		            onClick(picker) {
		              const date = new Date();
		              date.setTime(date.getTime() + 3600 * 1000 * 24 * 15);
		              picker.$emit('pick', date);
		            }
		        }, {
		            text: '30天',
		            onClick(picker) {
		              const date = new Date();
		              date.setTime(date.getTime() + 3600 * 1000 * 24 * 30);
		              picker.$emit('pick', date);
		            }
		        }]
		   	},
			disable_form:{
				ajax:false,
				msg:'',
				auto_disable:''
			},
	        rules: {
	          msg: [
	            { required: true, message: '请输入禁用原因', trigger: 'blur' },
	          ],
	        },
			search:{
				{notempty name=":request()->get('uid')"}
				search_type:'uid',
				key:'{:request()->get('uid')}',
				{elseif request()->get('user')/}
				search_type:'user',
				key:'{:request()->get('user')}',
				{elseif request()->get('mobile')/}
				search_type:'mobile',
				key:'{:request()->get('mobile')}',
				{elseif request()->get('email')/}
				search_type:'email',
				key:'{:request()->get('email')}',
				{else/}
				search_type:'uid',
				key:'',
				{/notempty}
				status:'all',
				role_type:'all',
				ajax:false,
				page:1,
				total:0,
				pageSize:10
			},
			tableData:[],
		},
		watch:{
		    view:XYBase.viewWatch,
		},
		created(){
			XYBase.created(this);
		},
	    methods: {
	    	toggleRoleType(row){
		        this.$confirm('确定将【'+row.nickname+'】的身份切换为【'+(row.role_type?'个人':'企业')+'】吗？', '提示', {
		        	dangerouslyUseHTMLString:true,
		          confirmButtonText: '切换',
		          cancelButtonText: '取消',
		          type: 'warning'
		        }).then(() => {
			    		$.getJSON('/user/setUserInfoRoleType/'+row.id+'/'+(row.role_type?0:1),function(ret){
			    			if (ret) {
			    				if (ret.code === 0) {
			    					row.role_type=row.role_type?0:1;
			    				}else{
			    					XYBase.msg(ret.msg);
			    				}
			    			}else{
								XYBase.error(XYBase.config.system_network_error);
			    			}
			    		});
		        }).catch(() => {
							XYBase.msg('已取消');
		        });
	    	},
	      	cancelRefuseWinSubmit(done){
	      		this.UserFind={};
	      		this.$refs.disable_form&&this.$refs.disable_form.resetFields();
	      		typeof done==='function'&&done();
				this.dialogVisible=false;
				this.userDialogVisible=false;
	      	},
	    	setStatus(data){
	    		if (data.status==2) return;
	    		if (data.status==1) {
	    			this.UserFind=data;
	    			this.dialogVisible=true;
	    		}else{
		    		var status=1,oldStatus=data.status;
		    		if (data.status) status=0;
		    		data.status=2;
		    		$.getJSON('/user/setStatus/'+data.id,function(ret){
		    			data.status=oldStatus;
		    			if (ret) {
		    				if (ret.code === 0) {
		    					data.status=status;
		    				}else{
		    					XYBase.msg(ret.msg);
		    				}
		    			}else{
							XYBase.error(XYBase.config.system_network_error);
		    			}
		    		});
	    		}
	    	},
	    	submitDisable(){
	    		var _this=this;
	    		if (this.UserFind.status==2) return;
	    		var status=1,oldStatus=this.UserFind.status;
	    		if (this.UserFind.status) status=0;
	    		this.UserFind.status=2;
	    		this.disable_form.ajax=true;
	    		$.ajax({
	    			url:'/user/setStatus/'+this.UserFind.id,
	    			data:this.disable_form,
	    			type:'post',
	    			dataType:'json',
	    			error:function(err) {
	    				_this.disable_form.ajax=false;
	    				_this.UserFind.status=oldStatus;
						XYBase.error(XYBase.config.system_network_error);
	    			},
	    			success:function(ret) {
	    				_this.disable_form.ajax=false;
		    			_this.UserFind.status=oldStatus;
		    			if (ret) {
		    				if (ret.code === 0) {
		    					_this.UserFind.status=status;
		    					_this.UserFind.disable_msg=_this.disable_form.msg;
		    					_this.cancelRefuseWinSubmit();
		    				}else{
		    					XYBase.msg(ret.msg);
		    				}
		    			}else{
							XYBase.error(XYBase.config.system_network_error);
		    			}
	    			}
	    		});
	    	},
			resetForm:function(formName) {
				this.$refs[formName].resetFields();
			},
			handleSizeChange(val) {
				this.search.page=1;
				this.search.pageSize=val;
	          	this.initHtml();
			},
			handleCurrentChange(val) {
				document.body.scrollIntoView();
				this.search.page=val;
	          	this.initHtml();
			},
			getUserInfo(row) {
				var _this=this;
	    		_this.UserFind=row;
				if (row.user_info)return _this.userDialogVisible=true;;
	    		$.getJSON('/getUserInfo/'+row.id,function(ret){
	    			if (ret) {
	    				_this.userDialogVisible=true;
	    				if (ret.code === 0) {
	    					row.user_info=1;
	    					row.data=ret.data;
	    				}else{
	    					row.user_info=2;
	    					XYBase.msg(ret.msg);
	    				}
	    				_this.UserFind=row;
	    			}else{
						XYBase.error(XYBase.config.system_network_error);
	    			}
	    		});
			},
			sendHtml(){
				this.search.page=1;
				this.initHtml();
			},
	      	initHtml() {
	      		var _this=this;
	      		_this.search.ajax=true;
				$.ajax({
					url:'',
					type:'get',
					data:_this.search,
					dataType:'json',
					error:function(err){
	      				_this.search.ajax=false;
						XYBase.error(XYBase.config.system_network_error);
					},
					success:function(ret){
	      				_this.search.ajax=false;
						if (ret) {
							if (ret.code === 0) {
								_this.search.total=ret.data.total;
								_this.tableData=ret.data.data;
							}else{
								XYBase.msg(ret.msg);
							}
						}else{
							XYBase.error(XYBase.config.system_network_error);
						}
					}
				});
			}
	    }
	});
	$(function(){
		vm.initHtml();
		reloadWindowSize();
		$(window).resize(function(){
			reloadWindowSize();
		});
	});
	function reloadWindowSize (argument) {
		var winW=$(window).width();
		if(winW <= 576){
			vm.labelPosition='top';
		}else{
			vm.labelPosition='right';
		}
	}
</script>
{/block}